import {createBrowserRouter,Navigate} from 'react-router-dom'

import Login from '../component/Login/Login'
import Home from '../component/Home/Home'
import Shou from '../component/Shou/Shou'
import Dingdan from '../component/Dingdan/Dingdan'
import Shu from '../component/Shuju/Shuju'
import Zhuce from '../component/Zhuce/Zhuce'
import Shezhi from '../component/Shezhi/Shezhi'
let Authcomponent =props=>{
  let Com=props.children.type
  if(sessionStorage.getItem('token')){
      return <Com></Com>
  }else{
      return <Navigate to='/login'/>
  }
}
const router = createBrowserRouter([
  {
    path:'/',
    element:<Navigate to='/login'/>
  },
  {
    path:'/home',
    element:<Home/>,
    children:[
      {
        path:'/home',
        element:<Navigate to='/home/shou'/>
      },
      {
        path:'/home/shou',
        element:<Authcomponent><Shou/></Authcomponent>
      },
      {
        path:'/home/dingdan',
        element:<Dingdan/>
      },
      {
        path:'/home/shuju',
        element:<Shu/>
      },
      {
        path:'/home/shezhi',
        element:<Shezhi/>
      }
    ]
  },
  {
    path:'/login',
    element:<Login/>
  },
  {
    path:'/zhuce',
    element:<Zhuce/>
  }
])
export default router